package com.lkd.job;

import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 自动补货工单的触发回调
 */
@Component
@Slf4j
public class SupplyJob {

    @Autowired
    private VendingMachineService vendingMachineService;

    @XxlJob("supplyJobHandler")
    public ReturnT<String> supplyJob(String param){
        log.info("定时处理补货工单开始");
        ShardingUtil.ShardingVO shardingVo = ShardingUtil.getShardingVo();
//        分片的总数
        int total = shardingVo.getTotal();
//        分片的索引
        int index = shardingVo.getIndex();
        log.info("total={},index={}",total,index);

//        查询售货机，创建自动补货消息
        vendingMachineService.doSupply(total,index);
        return ReturnT.SUCCESS;
    }
}
